﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;

/// <summary>
/// Summary description for QuangCaoProvider
/// CuongBH
/// 07/12/2011
/// </summary>
namespace EHTWebsite.Code
{
    public class QuangCaoProvider
    {
        public static void IUQuangCao(QuangCao theQuangCao, bool IsAdd)
        {
            SqlCommand command = new SqlCommand();
            command.CommandText = "proc_IUQuangCaos";
            command.CommandType = CommandType.StoredProcedure;
            command.Parameters.Add(new SqlParameter("@QuangCaoID", theQuangCao.QuangCaoID));
            command.Parameters.Add(new SqlParameter("@NoiDung", theQuangCao.NoiDung));
            command.Parameters.Add(new SqlParameter("@DeleteFlag",theQuangCao.DeleteFlag));
            command.Parameters.Add(new SqlParameter("@PhanVungID", theQuangCao.PhanVungID));
            command.Parameters.Add(new SqlParameter("@IsAdd", IsAdd));

            DataProvider.ExecuteNoneQuery(command);
        }
        public static void DeleteQuangCaoByQuangCaoID(Int32 SlideshowID)
        {
            SqlCommand command = new SqlCommand();
            command.CommandText = "proc_DeleteQuangCaoByQuangCaoID";
            command.CommandType = CommandType.StoredProcedure;
            command.Parameters.Add(new SqlParameter("@QuangCaoID", SlideshowID));

            DataProvider.ExecuteNoneQuery(command);
        }

        public static DataSet GetQuangCaos()
        {
            SqlCommand command = new SqlCommand();
            command.CommandText = "proc_GetQuangCaos";
            command.CommandType = CommandType.StoredProcedure;

            return DataProvider.ExecuteDataSet(command);
        }
        public static QuangCao GetQuangCaoByQuangCaoID(Int32 QuangCaoID)
        {
            SqlCommand command = new SqlCommand();
            command.CommandType = CommandType.StoredProcedure;
            command.CommandText = "proc_GetQuangCaoByQuangCaoID";
            command.Parameters.Add(new SqlParameter("@QuangCaoID", QuangCaoID));

            DataSet ds = DataProvider.ExecuteDataSet(command);
            QuangCao theQuangCao = null;

            if (ds.Tables[0].Rows.Count > 0)
            {
                theQuangCao = new QuangCao();
                theQuangCao.NoiDung = ds.Tables[0].Rows[0]["NoiDung"].ToString();
                theQuangCao.PhanVungID = Int32.Parse(ds.Tables[0].Rows[0]["PhanVungID"].ToString());
                theQuangCao.DeleteFlag = Boolean.Parse(ds.Tables[0].Rows[0]["DeleteFlag"].ToString());
                theQuangCao.QuangCaoID = Int32.Parse(ds.Tables[0].Rows[0]["QuangCaoID"].ToString());
            }

            return theQuangCao;
        }

        public static QuangCao GetQuangCaoByPhanVungID(Int32 PhanVungID)
        {
            SqlCommand command = new SqlCommand();
            command.CommandType = CommandType.StoredProcedure;
            command.CommandText = "proc_GetQuangCaoByPhanVungID";
            command.Parameters.Add(new SqlParameter("@PhanVungID", PhanVungID));

            DataSet ds = DataProvider.ExecuteDataSet(command);
            QuangCao theQuangCao = null;

            if (ds.Tables[0].Rows.Count > 0)
            {
                theQuangCao = new QuangCao();
                theQuangCao.NoiDung = ds.Tables[0].Rows[0]["NoiDung"].ToString();
                theQuangCao.PhanVungID = Int32.Parse(ds.Tables[0].Rows[0]["PhanVungID"].ToString());
                theQuangCao.DeleteFlag = Boolean.Parse(ds.Tables[0].Rows[0]["DeleteFlag"].ToString());
                theQuangCao.QuangCaoID = Int32.Parse(ds.Tables[0].Rows[0]["QuangCaoID"].ToString());
            }

            return theQuangCao;
        }
    }
}